﻿<cfsilent>
	<cfscript>
		
		jsonAdvice = getProperty("serviceFactory").getBean("jsonAdvice");
		response = structNew();
		
		transaction {
			
			sql = "SELECT  a.cls_name,
						   a.cls_size,
              			   a.campus_id 
					FROM t_class a 
					WHERE a.cls_id = :classId ";
			queryObj = new Query( datasource=application.dnsMaster ) ;
			queryObj.addParam( name="classId", value=event.getArg("CID"), cfsqltype="cf_sql_char" );
			rs_class = queryObj.execute( sql=sql ).getResult();
			className = rs_class.cls_name;
			PlanSize = rs_class.cls_size;
			Campus = rs_class.campus_id ;
			
			if ( event.isArgDefined("Name") ) {
				className = event.getArg("Name");
			}
			
			if ( event.isArgDefined("PlanSize") and isNumeric( event.getArg("PlanSize") ) ) {
				PlanSize = event.getArg("PlanSize"); 
			}
			
			if ( event.isArgDefined("CampusID") ) {
				Campus = event.getArg("CampusID");
			}
			
			sql = "UPDATE t_class a 
					SET a.cls_name = :className ,
						a.cls_size = :PlanSize ,
						a.campus_id = :Campus 
					WHERE a.cls_id = :classId 
					";
			queryObj = new query( datasource=application.dnsMaster );
			queryObj.addParam( name="className", value= className , cfsqltype="cf_sql_varchar" );
			queryObj.addParam( name="PlanSize", value=PlanSize, cfsqltype="cf_sql_interger" );
			queryObj.addParam( name="Campus", value=Campus, cfsqltype="cf_sql_char" );
			queryObj.addParam( name="classId", value=event.getArg("CID"), cfsqltype="cf_sql_char" );
			queryObj.execute( sql=sql );	
			
			sql = "SELECT   a.cls_id,
							a.cls_name,
							a.cls_size,
							b.campus_id,
							b.campus_name 
					FROM t_class a 
               			 INNER JOIN t_campus b ON b.campus_id = a.campus_id 
					WHERE a.cls_id = :classId ";
			queryObj = new Query( datasource=application.dnsMaster ) ;
			queryObj.addParam( name="classId", value=event.getArg("CID"), cfsqltype="cf_sql_char" );
			rs_classNow = queryObj.execute( sql=sql ).getResult();
			
			class = structNew();
			structInsert(class, "ClassID", rs_classNow.cls_id);
			structInsert(class, "Name", rs_classNow.cls_name);
			structInsert(class, "PlanSize", rs_classNow.cls_size);
		
			campus = structNew();
			structInsert(campus, "CampusID", rs_classNow.campus_id);
			structInsert(campus, "CampusName", rs_classNow.campus_name);
		
			structInsert(response, "formClass", class);
			structInsert(response, "campus", campus);
		}
		
	</cfscript>
</cfsilent><cfoutput>#jsonAdvice.encode(data:response, stringNumbers:true)#</cfoutput>